package net.wds.study.clazz.controller;

import net.sf.json.JSONObject;
import net.wds.study.clazz.entity.Clazz;
import net.wds.study.clazz.service.ClazzService;
import net.wds.study.clazz.utils.PageModel;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by gf on 2020/9/8.
 */
@Controller
@RequestMapping("/clazz")
public class CalzzController {


    @Resource
    private ClazzService clazzService;

    /**
     * @Author GongFan
     * @Description  班级信息分页查询控制器
     * @Date 2020/9/8 20:02
     * @Param [startIndex, pageSize, clazzMajor, clazzYear, clazzLeader, clazzStatus, response]
     * @return void
     **/
    @RequestMapping(value = "/getPage" ,method = {RequestMethod.POST})
    private void getPage(
            @RequestParam Integer startIndex,
            @RequestParam Integer pageSize,
            @RequestParam String clazzMajor,
            @RequestParam String clazzYear,
            @RequestParam String clazzLeader,
            HttpServletResponse response){


        PageModel<Clazz> pageModel=clazzService.getPageByParams(startIndex,pageSize,clazzMajor,clazzYear,clazzLeader);
        try {
            //将结果集转换成JSON对象返回客户端
            response.getWriter().write(JSONObject.fromObject(pageModel).toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
